package com.example.demo;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

public class ThreadException {
    static class MyTask implements Callable {
        @Override
        public Object call() throws Exception {
            System.out.println("执行线程");
            //制造异常
//            int a = 3/0;
//            return "1";
            return null;
        }
    }
    public static void main(String[] args) {
        FutureTask<String> futureTask = new FutureTask<>(new MyTask());
        new Thread(futureTask).start();
        //通过get方法捕获异常
        try {
            String s = futureTask.get();
            System.out.println(s);
        }catch (Exception e) {
            System.out.println("捕获到异常了");
        }
    }
}
